<!DOCTYPE html>
<html class="x-admin-sm" xmlns:th="http://www.thymeleaf.org">
    
    <head>
        <meta charset="UTF-8">
        <title>欢迎页面-X-admin2.2</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
        <link th:href="@{/css/font.css}" rel="stylesheet"/>
        <link th:href="@{/css/xadmin.css}" rel="stylesheet"/>
        <script th:src="@{/lib/layui/layui.js}" charset="utf-8"></script>
        <script th:src="@{/js/xadmin.js}" type="text/javascript" charset="utf-8"></script>
        <script th:inline="javascript"> var ctx = [[@{/}]];</script>
        <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
        <!--[if lt IE 9]>
            <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
            <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
        <![endif]-->
    </head>
    <body>
        <div class="layui-fluid">
            <div class="layui-row">
                <form class="layui-form">
                  <div class="layui-form-item">
                      <label for="roleName" class="layui-form-label">
                          <span class="x-red">*</span>角色名称
                      </label>
                      <div class="layui-input-inline">
                          <input type="text" id="roleName" name="roleName" required="" lay-verify="required"
                          autocomplete="off" class="layui-input">
                      </div>

                  </div>

                  <div class="layui-form-item">
                    <label for="roleKey" class="layui-form-label">
                        <span class="x-red">*</span>英文名称
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="roleKey" name="roleKey" required=""
                               autocomplete="off" class="layui-input">
                    </div>
                </div>
                    <div class="layui-form-item">
                        <label for="roleSort" class="layui-form-label">
                            <span class="x-red">*</span>显示顺序
                        </label>
                        <div class="layui-input-inline">
                            <input type="text" id="roleSort" name="roleSort" required=""
                                   autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label for="roleKey" class="layui-form-label">
                            <span class="x-red">*</span>角色状态
                        </label>
                        <div class="layui-input-block">
                            <input type="checkbox" id="status" name="status" lay-skin="switch" lay-text="ON|OFF" checked>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label"><span class="x-red">*</span>菜单权限</label>
                        <div class="layui-input-block">
                            <div id="test12" class="demo-tree-more"></div>
                        </div>

                    </div>

                  <div class="layui-form-item">
                      <label  class="layui-form-label">
                      </label>
                      <button  class="layui-btn" lay-filter="add" lay-submit="">
                          增加
                      </button>
                  </div>
              </form>
            </div>
        </div>
<script th:inline="javascript">
  layui.use(['form', 'layer','tree'],function() {
                var form = layui.form,
                layer = layui.layer,
                tree = layui.tree;

 //树形菜单
  tree.render({
    elem: '#test12'
    ,data: [[${treeData}]]
    ,showCheckbox: true  //是否显示复选框
    ,id: 'demoId1'
    //,isJump: true //是否允许点击节点时弹出新窗口跳转
    ,click: function(obj){
      var data = obj.data;  //获取当前点击的节点数据
      layer.msg('状态：'+ obj.state + '<br>节点数据：' + JSON.stringify(data));
    }
  });
            //监听提交
            form.on('submit(add)',
                function(data) {
                    //console.log(data);
                    if(data.field.status!= null&&data.field.status=='on'){
                        data.field.status = 0;
                    }else{
                        data.field.status = 1;
                    }
                    //var checkedData = tree.getChecked('demoId1'); //获取选中节点的数据
                    //发异步，把数据提交给php
                     $.ajax({   
                url:'/system/role/addRole',       
                method:'post',    
                      data:data.field,                          
                 dataType:'JSON',         
                  success:function(res){       
                    if(res.code == '0'){
                                //console.log(res)                                  
                                layer.alert("增加成功", {icon: 8},
                                function() {
                                    //关闭当前frame
                                    xadmin.close();
                                    // 可以对父窗口进行刷新
                                    xadmin.father_reload();
                                });           
                 } else{
                                layer.alert("增加失败", {icon: 8},
                                function() {
                                    //关闭当前frame
                                    xadmin.close();
                                    // 可以对父窗口进行刷新
                                    xadmin.father_reload();
                                });      
                              }                                           
             }              
             }) ;  
                    return false;
                });

            });
        </script>

    </body>

</html>
